package org.raymond.iworks.study.netty.atguigu.netty.sticky;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.net.InetSocketAddress;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
public class StickyClient {
    public static void main(String[] args) throws Exception {
        int port = 6666;
        EventLoopGroup workGroup = new NioEventLoopGroup();

        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(workGroup)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline().addLast(new StickyClientHandler());
                        }
                    });

            ChannelFuture cf = bootstrap.connect(new InetSocketAddress(port)).sync();
            cf.channel().closeFuture().sync();
        } finally {
            workGroup.shutdownGracefully();
        }
    }
}
